package com.tnovoselec.android.mojevijesti.dto;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class NewsResultHolder {
	
	private static Map<String, List<NewsItemDto>> RESULT = new LinkedHashMap<String,  List<NewsItemDto>>();
	
	private NewsResultHolder(){}
	
	public static void clear() {
		NewsResultHolder.RESULT.clear();
	}
	
	public static void put(String key, List<NewsItemDto> items){
		RESULT.put(key, items);
	}

	public static Map<String, List<NewsItemDto>> getAll() {
		return RESULT;
	}
	public static List<NewsItemDto> get(String key){
		return RESULT.get(key);
	}
	
	public static List<NewsItemDto> get(int position){
		Iterator<String> iter = RESULT.keySet().iterator();
		int i = 0;
		while (iter.hasNext()){
			String title = iter.next();
			if (i == position){
				return RESULT.get(title);
			}
			i++;
		}
		return null;
	}
	
	public static String getTitleByPosition(int position){
		Iterator<String> iter = RESULT.keySet().iterator();
		int i = 0;
		while (iter.hasNext()){
			String title = iter.next();
			if (i == position){
				return title;
			}
			i++;
		}
		return null;
	}

}
